(function(w) {
    var app = {};
    w.app = app;
}(window));

(function(w) {
    var options = {
        striped: true,
        cache: true,
        pagination: true,
        pageSize: 10,
        pageNumber: 1,
        pageList: [10, 20, 50],
        search: true,
        searchOnEnterKey: true,
        strictSearch: true,
        showHeader: true,
        showFooter: false,
        showRefresh: true,
        showColumns: true,
        searchAlign: 'right',
        toolbarAlign: 'left',
        checkboxHeader: true,
        clickToSelect: true,
        uniqueId: "id",
        sidePagination: 'server',
    }

    function table(el, option) {
        this.el = $(el);
        this.options = Object.assign({}, options, option);

        this.setTool();
        this.setCheckbox();
        this.el.bootstrapTable(this.options);
    }
    table.prototype.init = function(el, option) {

    }
    table.prototype.setCheckbox = function() {
        if (this.options.checkbox) {
            this.options.columns.unshift({
                field: this.options.checkbox,
                checkbox: true,
            })
        }
    }
    table.prototype.setTool = function() {
        if (this.options.toolbar) {
            this.toolbar = $(this.options.toolbar);
        }
    }
    table.prototype.getIds = function() {
        return $.map(this.el.bootstrapTable('getSelections'), function(row) {
            return row.name;
        });
    }
    table.prototype.stateFormatter = function(value, row, index) {
        return value;
    }
    w.app.table = table;
}(window));

(function(w) {
    w.app.layerIframe = function(title, url) {
        return layer.open({
            title: title || '在线调试',
            type: 2,
            content: url || "iframe.html",
            skin: 'layer_auto',
            offset: ['0px', '0px'],
            area: ['100%', '100%']
        })
    }
    w.app.layeriframeo = function(options) {
        return layer.open(options)
    }
    w.app.layeralert = function(title, con) {
        return layer.open({
            title: title || '',
            content: con || ''
        });
    }
    w.app.layeropen = function(options) {
        return layer.open(options)
    }
    w.app.layermsg = function(title) {
        return layer.msg(title);
    }
    w.app.layerconfirm = function(title, con) {
        return layer.confirm(con, {
            title: title,
            btn: ['确定', '删除'] //按钮
        }, function(index) {
            layer.close(index);
        }, function(index) {

        });
    }
    w.app.layertab = function(w, h, tab) {
        return layer.tab({
            area: [w || '600px', h || '300px'],
            tab: tab
        });
    }
    w.app.layerprompt = function(title, type, call) {
        return layer.prompt({ title: title, formType: type || 1 }, function(pass, index) {
            layer.close(index);
            call && call(pass, index);
        });
    }
}(window));
(function(w) {
    function tree(options) {
        this.options = options;
        this.options.elem = this.options.ele;
        this.ele = $(this.options.ele)
        this.get();
    }
    tree.prototype.get = function() {
        $.get(this.options.url).then(function(res) {
            this.options.nodes = res;
            this.render();
        }.bind(this))
    }
    tree.prototype.render = function() {
        layui.tree(this.options);
    }
    w.app.tree = tree;
}(window));
(function(w) {
    function nav(options) {
        this.options = options;
        this.ele = $(this.options.ele)
        this.get();
    }
    nav.prototype.get = function() {
        $.get(this.options.url).then(function(res) {
            this.options.data = res;
            this.render();
        }.bind(this))
    }
    nav.prototype.render = function() {
        this.ele.html(_.template(this.temp)({ data: this.options.data }));
        this.bind();
    }
    nav.prototype.bind = function() {
        var ele = this.ele;
        this.ele.find('.menu_tit').on('click', function() {
            ele.find('li').removeClass('active');
            $(this).parent().toggleClass('active')
        })
    }
    nav.prototype.temp = '<% _.each(data,function(item){%>' +
        '<li class="<%=item.class%>"><a class="menu_tit" href="javascript:" ><%=item.name%></a><ul>' +
        '<%_.each(item.childer,function(obj){%>' +
        '<li class="<%=obj.class%>"><a href="<%=obj.href%>" class="" target="<%=obj.target%>"><%=obj.name%></a></li>' +
        '<%})%></ul></li>' +
        '<%})%>'
    w.app.nav = nav;
}(window));
(function(w) {
    var bind = {}
    bind.closeiframe = function() {
        window.parent.app.bind.closeparent();
    }
    bind.closeparent = function() {
        $('.layui-layer,.layui-layer-shade').remove();
    }
    w.app.bind = bind;
}(window));
(function(w) {
    function scrolldiv(el, options) {
        this.el = $(el);
        this.options = options || 0;
        this.set();
    }

    scrolldiv.prototype.set = function() {
        this.top = this.el.offset().top;
        $('body').on('click', function() {
            setTimeout(function() {
                this.top = this.div.offset().top;
            }.bind(this), 500)
        }.bind(this))

        if (this.options && this.options.height) {
            this.height = this.options.height;
        } else {
            this.height = this.el.height();
        }
        this.div = $('<div></div>');
        this.div.css({ height: 0 + 'px' }) //.hide();
        this.el.before(this.div);
        if (this.options && this.options.class) {
            this.class = this.options.class;
        } else {
            this.class = 'fixed';
        }

        $(window).on('scroll', function(e) {
            this.scroll();

        }.bind(this))
    }
    scrolldiv.prototype.scroll = function() {
        this.scrolltop = $(window).scrollTop();
        if (this.scrolltop < 120) {
            this.top = this.div.offset().top;
        }
        if (this.scrolltop > this.top) {
            this.el.addClass(this.class);
            this.div.css({ height: this.height + 'px' });
            if (g_head_bool == 0) {
                $('.switch_large input').attr('checked', false);
                g_headhide();
            }

        } else {
            this.el.removeClass(this.class)
            this.div.css({ height: '0px' });
        }
    }
    w.app.scrolldiv = scrolldiv;
}(window));
(function(w) {
    w.app.onbind = function() {
        $(".stretch-push").on('click', function() {
            $(this).parent().parent().parent().find('.fpart').fadeToggle();
            $(this).toggleClass('current')
        });

        $('input[action=date]').datetimepicker({ minView: "month", format: 'yyyy-mm-dd' });
        $('input[action=datetime]').datetimepicker();
    }
}(window));
(function(w) {
    w.app.check_group = function() {
        $('.check_group').on('click', 'a', function() {
            $(this).parent().find('a').removeClass('active');
            $(this).addClass('active');
            $(this).parent().parent().find('input').eq(0).val($(this).attr('value'))
        })
    }
}(window));
(function(w) {
    function tableupdate(options) {
        this.options = options;
        this.one = false;
        this.ele = $(this.options.ele);

        this.get();
        this.search = this.options.search || { pagesize: 10 };
        if (this.options.searchele) {
            this.searchsubmit();
        }
        if (this.options.pageele) {
            this.pageele = $(this.options.pageele)
                //this.setpage();
        }
    }
    tableupdate.prototype.setpage = function() {
        var that = this;
        that.Page = this.pageele.Paging({
            pagesize: this.search.pageSize,
            count: this.search.total,
            callback: function(page, size, count) {
                //console.log(arguments)
                that.search.page = page;
                //that.Page[0].render({current:page})
                that.get();
            }
        });

        //console.log(that.Page[0].render)
    }
    tableupdate.prototype.searchsubmit = function() {
        var that = this;
        this.sear = $(this.options.searchele);
        this.sear.on('click', '[action="search"]', function() {
            //console.log('s')
            that.sear.find('input').each(function() {
                that.search[$(this).attr('name')] = $(this).val();
            })
            that.sear.find('select').each(function() {
                //console.log($(this).attr('name'),$(this).val())
                that.search[$(this).attr('name')] = $(this).val();
            })
            that.subbool = true;
            that.search.page = 1;

            console.log(that.search);
            that.get();
        })

    }
    tableupdate.prototype.get = function() {
        var that = this;
        $.get(this.options.url, this.search, function(res) {
            that.data = res.rows;
            that.search.total = res.total;
            that.search.page = res.page;
            if (that.options.call) {
                that.options.call(res);
            }
            that.temphead();
            if (that.one == false) {
                that.setpage();
                that.one = true;
            }
            //if(that.search.page<2){
            that.Page[0].render({ current: that.search.page, count: that.search.total })
                //}
        })
    }
    tableupdate.prototype._set = function() {
        this.ele.find('thead').find('th').each(function(i, ele) {
            $(this).css({ width: $(this).outerWidth() + 'px' })
        })
    }
    tableupdate.prototype.bind = function() {
        var that = this;
        this.ele.on('click', '[action="table_update"]', function(e) {
            var tr = $(this).parents('tr').eq(0);
            tr.addClass('edit')

        });
        this.ele.on('click', '[action="table_save"]', function(e) {
            var ar = $(this).parents('tr').eq(0)
            var id = ar.attr('data-id');
            var d = '';
            for (var i = 0; i < that.data.length; i++) {
                if (that.data[i].id == id) {
                    d = that.data[i]
                }
            }
            ar.find('input').each(function() {
                    var val = $(this).val();
                    var name = $(this).attr('name')
                    d[name] = val;
                })
                //console.log(d);
            $.post(that.options.save, d, function(res) {
                res = JSON.parse(res);
                if (res.errorCode == 0) {
                    that.get();
                }
            })
        })
        this.ele.on('click', '[action="table_delete"]', function(e) {
            var ar = $(this).parents('tr').eq(0)
            var id = ar.attr('data-id');

            $.get(that.options.delete, { id: id }, function(res) {
                if (typeof res == "string") {
                    res = JSON.parse(res);
                }

                console.log(res)
                if (res.errorCode == 0) {
                    ar.remove();
                }
            });
        })
        this.ele.on('click', '[action="table_cancel"]', function(e) {
            var tr = $(this).parents('tr').eq(0);
            tr.removeClass('edit');
        })
        this.ele.on('click', '[action="href"]', function(e) {
            //console.log('a')
            var id = $(this).attr('data-id') || $(this).parents('tr').attr('data-id');
            var data = that.getid(id);
            var href = $(this).attr('data-href');
            if (data != null) {
                //console.log(data,href)
                var t = _.template(href)({ data: data });
                console.log(t);
                location.href = t;
            }
        })
        this.ele.on('click', '[action="iframeopen"]', function(e) {
            //console.log('a')
            var id = $(this).attr('data-id') || $(this).parents('tr').attr('data-id');
            var data = that.getid(id);
            var href = $(this).attr('data-href');
            var skin = $(this).attr('data-skin');
            var title = $(this).attr('data-title');
            var area = $(this).attr('data-area').split(',');


            if (data != null) {
                //console.log(data,href)
                var t = _.template(href)({ data: data });
                console.log(t);
                app.layeriframeo({
                        type: 2,
                        skin: skin, //样式类名
                        title: title,
                        shadeClose: true,
                        shade: 0.3,
                        area: area,
                        content: t //iframe的url
                    })
                    //location.href=t;
            }
        })
    }
    tableupdate.prototype.getid = function(id) {
        for (var i = 0; i < this.data.length; i++) {
            if (id == this.data[i].id) {
                return this.data[i]
            }
        }
        return null;
    }
    tableupdate.prototype.temphead = function() {
        var t = _.template($('#temp1').html())({
            columns: this.options.columns,
            data: this.data,
            action: this.options.action
        });
        this.ele.html(t);
        this.body = this.ele.find('tbody');
        this.ele = $(this.options.ele)
        this.bind();
        this._set();
    }
    w.app.tableupdate = tableupdate;
}(window));
(function(w) {
    function init() {
        this.onbind();
        this.check_group();
        this.table1b();

    }
    w.app.init = init;
}(window));
(function(w) {

    w.app.select = function(val, name, dataname) {
        var t = _.template('<select name="<%=obj.name%>"><% _.each(data,function(item){%><% if(item.id==obj.val){%><option value="<%=item.id%>" selected><%=item.name%></option><%} else{%><option value="<%=item.id%>"><%=item.name%></option><%}%><%})%></select>')({ data: D[dataname], val: val, name: name })
            // console.log(t);
        $(t).val(val)
        return t;
    }
    w.app.getselect = function(val, dataname) {
        var t = '';
        var d = D[dataname]
        for (var i = 0; i < d.length; i++) {
            if (d[i].id == val) {
                t = d[i].name;
            }
        }
        return t;
    }
    w.app.getselectclass = function(val, dataname) {
        if (dataname == undefined) {
            return '';
        }
        var t = '';
        var d = D[dataname]
        for (var i = 0; i < d.length; i++) {
            if (d[i].id == val) {
                t = d[i].class || '';
            }
        }
        return t;
    }
}(window));
(function(w) {
    w.app.table1b = function() {
        $(document).on('click', '.table .table_more', function() {
            $(this).parents('tbody').toggleClass('current')
        }).on('click', '.table-cheall', function() {
            console.log($(this).is(":checked"))
            if ($(this).is(":checked")) {
                $(this).parents('table').find('.table-che').prop('checked', true)
            } else {
                $(this).parents('table').find('.table-che').prop('checked', false)
            }
        }).on('click', '.span_1', function() {
            $(this).parents('tbody').toggleClass('current')
        }).on('click', '.td-route', function() {
            $(this).parents('tbody').toggleClass('current')
        })
        $('.cert-item').on('click', '.span_more', function() {
            var i = $(this).parents('li').index();
            i += 1;
            console.log(i);
            var s = $(this).parents('.fpart').find('.cert-manage');
            s.eq(i).show();
        })
        if ($('#container').length > 0) {
            var ue = UE.getEditor('container');
        }
        $('#tree_label').on('click', 'input[type="checkbox"]', function() {

            var c = $(this).attr('action');
            var a = $(this).is(':checked');
            if (c == 'child') {
                //console.log('child');
                var input = $(this).parents('li').find('ul input');
                if (a) {
                    for (var i = 0; i < input.length; i++) {
                        input.eq(i).prop('checked', true)
                    }
                } else {
                    for (var i = 0; i < input.length; i++) {
                        input.eq(i).prop('checked', false)
                    }
                }
            } else {
                if (a == false) {
                    //console.log($(this).parents('.ul'))
                    var lis = $(this).parents('.ul').find('input');
                    var le = lis.length;
                    var u = 0;
                    for (var i = 0; i < lis.length; i++) {
                        if (lis.eq(i).is(':checked') == false) {
                            u += 1;
                        }
                    }
                    //console.log(u,le);
                    if (u == le) {
                        var bs = $(this).parents('.ul').parent().find('a input');
                        bs.prop('checked', false);
                    }
                } else {
                    var lis = $(this).parents('.ul').find('input');
                    var le = lis.length;
                    var u = 0;
                    for (var i = 0; i < lis.length; i++) {
                        if (lis.eq(i).is(':checked') == true) {
                            u += 1;
                        }
                    }
                    //console.log(u,le);
                    if (u == le) {
                        var bs = $(this).parents('.ul').parent().find('a input');
                        bs.prop('checked', true);
                    }
                }
            }
            //console.log(a);
        })
        $('.a_s1').on('click', function() {
            $('.a_s1').removeClass('current')
            $(this).addClass('current');
        })
        $('.radio_change').on('click', function() {
            var t = $('.radio_change:checked').val();
            var d = $('.radio_change').attr('data-action')
                //console.log(d);
            if (t == 1) {
                $(d).removeClass('hide');
            } else {
                $(d).addClass('hide');
            }
        })
        $('.table-1b').on('click', '[action="tabshow"]', function() {
            var id = $(this).attr('data-id');
            console.log(id);
            var tbody = $(this).parents('tbody')
            tbody.toggleClass('current');
            $(this).parent().toggleClass('current')
            tbody.find('.tabsu').hide();
            if (tbody.hasClass('current')) {
                tbody.find('.tabsu').eq(id).show();
            }
        }).on('click', '.table_more', function() {
            $(this).parents('tbody').find('.td-routeu').removeClass('current')
            $(this).parents('tbody').find('.tabsu').hide();
        })
        $('body').on('click', '.magnify-pre', function() {
            var tabst1 = $('.tabst1');

            var t = $(this).parents('.tabst1').prev()
            if (t.length > 0) {
                tabst1.addClass('hide')
                t.removeClass('hide');
            }
        }).on('click', '.magnify-next', function() {
            var tabst1 = $('.tabst1');
            var t = $(this).parents('.tabst1').next()
            if (t.length > 0) {
                tabst1.addClass('hide')
                t.removeClass('hide');

            }
        })

        $('body .fh-radio').on('click', 'input[type="radio"]', function() {
            if ($(this).get(0).checked) {
                var t = $(this).val();
                if (t == 1) {
                    $(this).parents('.cert-info').find('.cert-manage').addClass('hides')
                } else {
                    $(this).parents('.cert-info').find('.cert-manage').removeClass('hides')
                }
            }
        })
        w.app.ontree();
        w.app.ontreeb();
    }
    w.app.ontree = function() {
        $('.left-tree').on('click', '.table_more', function() {
            $('.left-tree').toggleClass('show')
        }).on('click', 'a', function() {
            $(this).parent().toggleClass('show')
        })
        $('.ul_msglist').on('click', 'a.green-button', function() {
            $(this).parents('li').toggleClass('show')
            var t = $(this).html();
            var u = $(this).attr('data-show');
            if (u == true) {
                console.log(t);
                if (t.indexOf("查看") > -1) {
                    t = "收起<i>|</i>"
                } else {
                    t = "查看<i>|</i>"
                }
                $(this).html(t);
            }

        })
        $('.chart').on('click', '.chart-left', function() {
            $(this).parent().toggleClass('active');
        }).on('click', '.icon-toggle', function() {
            if (!$(this).hasClass('hiddens')) {
                $('.icon-toggle').removeClass('hiddens');
                $('.bor-line-1').addClass('hide');
                $('.right-tabel').removeClass('hide');
            } else {
                $('.right-tabel').addClass('hide');
            }


            $(this).toggleClass('hiddens')
            $(this).parent().find('.bor-line-1').toggleClass('hide')
            var t = $(this).offset()
            console.log(t);
            var ta = $('.right-tabel').eq($(this).attr('data-id'))
            var tx = t.top - 132;
            ta.css({ top: tx + 'px' });
            ta.toggleClass('hide')
        }).on('click', '.fbtn', function() {
            $(this).parent().find('.more').toggle();
        }).on('click', '.more p', function() {
            $(this).parent().toggle();
        })
        $('.box_tabc').on('click', '.a_su1', function() {
            $(this).parents('.box_tabc').toggleClass('cur')
        }).on('click', '.table_more', function() {
            $(this).parents('.box_tabc').toggleClass('cur')
        })
        $('.fb-add').click(function() {
            $('.box_tabc .a_su1').click()
        })
    }
    w.app.ontreeb = function() {
        var tbody = $('.table').find('tbody')
        $('#box_tree_table').on('click', '.table-che', function() {
            //return ;
            var t = $(this).is(':checked');
            if (t) {
                var d = $(this).parent().attr('data-obj');
                // console.log(d);
                d = JSON.parse(d);
                var u = _.template($('#temp2').html())({ obj: d });
                //console.log(u);
                tbody.append(u);

            } else {
                var d = $(this).parent().attr('data-obj');
                //console.log(d);
                d = JSON.parse(d);
                var tr = tbody.find('tr');
                for (var i = 0; i < tr.length; i++) {
                    if (tr.eq(i).attr('data-id') == d.id) {
                        tr.eq(i).remove();
                    }
                }
            }
        })
        $('.table').on('click', 'i.prev', function() {
            var i = $(this).parent().find('input');
            var min = Number(i.attr('data-min'));
            var t = Number(i.val());
            if (t > min) {
                t -= 1;
            }
            i.val(t);
        })
        $('.table').on('click', 'i.next', function() {
            var i = $(this).parent().find('input');
            var t = Number(i.val());
            var max = Number(i.attr('data-max'));
            if (t < max) {
                t += 1;
            }
            i.val(t);
        })
        $('.ul_list3').on('click', '.icon-tog', function() {
            $(this).parents('li').toggleClass('current')
        })
    }

}(window));



(function(w) {
    w.app.contrast = function(el) {
        var el = $(el);
        el.find('.contrast').remove();
        el.find('.input-con-color').removeClass('input-con-color');
        el.find('.input-contrast').removeClass('input-contrast')
        el.find('.contrast_bor,img').removeClass('contrast_bor')

        el.find('input,select,textarea').each(function(index, el) {
            var l = $(el);
            var old = l.attr('data-old');
            var par = l.parents('.input-group,.parcon_1,.box_datab');

            if (old && old.length > 0) {
                if (par.length == 0 || $(this).get(0).tagName == "TEXTAREA") {
                    l.addClass('input-con-color')
                } else {
                    par.addClass('input-contrast');
                    $(this).before('<i class="contrast"></i>')
                }
            }
        });
        el.find('.cp-box,img').each(function(index, el) {
            var old = $(el).attr('data-old');
            if (old && old.length > 0) {
                $(el).addClass('contrast_bor')
            }
        })
        el.on('mouseover', 'i.contrast', function() {
            var t = $(this).parent().find('input,select');
            if ($(this).parent().hasClass('form-required')) {
                $('.contrastbox').addClass('contrastbox_required')
            } else {
                $('.contrastbox').removeClass('contrastbox_required')
            }
            var old = t.attr('data-old'),
                oldb = t.attr('data-oldb');
            var off = $(this).offset();
            var par = $(this).parent();
            var top = off.top - 67 + 'px';
            var left = off.left - par.width() + 36 + 'px';
            if ($(this).parent().hasClass('parcon_1')) {
                left = off.left - par.width() + 27 + 'px';
            }

            if (old && old.length > 0) {
                //console.log(off,par.width());
                var p = $('.contrastbox').find('p');
                p.eq(0).find('i').html(old);
                p.eq(1).find('i').html(oldb);
                $('.contrastbox').css({ top: top, left: left, width: par.width() + 'px' }).removeClass('hide')
            }
        }).on('mouseout', 'i.contrast', function() {
            $('.contrastbox').addClass('hide')
        })
    }
}(window));

(function(w) {
    function mapline(el, adrs) {
        $('body').append('<div class="idmaphide"><div id="idmaphide"></div></div>')
        var map = new BMap.Map(el || "allmap"); // 创建Map实例
        map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
        var top_right_navigation = new BMap.NavigationControl({ anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL });
        map.addControl(top_right_navigation);
        //line('106.557165,29.570997',['112.945333,28.233971','116.348215,39.732495','108.946306,34.347436']);
        getadds(adrs || ['重庆', '北京大兴瑞海二区', '太原', '长沙', '青岛'], function(arr) {
            line(arr.shift(), arr);
        });

        function line(pt, pts) {
            var p = pt.split(',')[0],
                t = pt.split(',')[1];
            addicon(p, t, 'images/mp2_03.png', 34, 44);
            addtext(p, t, '[总仓]');
            var pointA = new BMap.Point(p, t); // 开始
            for (var i = 0; i < pts.length; i++) {
                var p1, t1;
                p1 = pts[i].split(',')[0];
                t1 = pts[i].split(',')[1];
                var pointB = new BMap.Point(p1, t1); // 结束
                var m = (map.getDistance(pointA, pointB) / 1000).toFixed(2); //获取两点距离,保留小数点后两位
                var polyline = new BMap.Polyline([pointA, pointB], {
                    strokeColor: "#4fa1a4",
                    strokeWeight: 6,
                    strokeOpacity: 0.8
                }); //定义折线
                map.addOverlay(polyline); //添加折线到地图上
                addicon(p1, t1, 'images/mp2_06.png', 34, 44);
                addtext(p1, t1, '[建议]<br/>' + m + '公里');
            }
            map.centerAndZoom(new BMap.Point(p, t), 7);
        }

        function addtext(p, t, text) {
            var opts = {
                position: new BMap.Point(p, t),
                offset: new BMap.Size(20, -20)
            }
            var label = new BMap.Label(text, opts);
            label.setStyle({
                color: "#fff",
                fontSize: "14px",
                lineHeight: "20px",
                border: '0px',
                padding: '4px',
                background: 'rgba(0,0,0,0.3)'
            });
            map.addOverlay(label);
        }

        //添加icon
        function addicon(p, t, img, w, h) {
            var pt = new BMap.Point(p, t);
            var icon = new BMap.Icon(img, new BMap.Size(w, h));
            icon.setAnchor(new BMap.Size(18, 55))
            var marker = new BMap.Marker(pt, { icon: icon })
            map.addOverlay(marker);

            var icon1 = new BMap.Icon('images/mp2_11.png', new BMap.Size(20, 20));
            icon1.setAnchor(new BMap.Size(10, 10))
            var marker1 = new BMap.Marker(pt, { icon: icon1 })
            map.addOverlay(marker1);

        }
        //获取pt
        function getadds(val, call) {
            var idmaphide = new BMap.Map("idmaphide");
            idmaphide.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
            var localSearch = new BMap.LocalSearch(idmaphide);
            var arr = [];
            var index = -1;
            localSearch.enableAutoViewport();
            localSearch.setSearchCompleteCallback(function(searchResult) {　　　　
                var poi = searchResult.getPoi(0);　　　　 //console.log(poi.point.lng + "," + poi.point.lat);   
                arr.push(poi.point.lng + "," + poi.point.lat)
                if (arr.length == val.length) {
                    call(arr);
                } else {
                    ua();
                }　　
            });
            //for(var i=0;i<val.length;i++){
            //localSearch.search(val[i]);
            //}

            function ua() {
                if (index < val.length - 1) {
                    index++;
                    localSearch.search(val[index])
                }
            }
            ua();
        }
    }
    w.app.mapline = mapline;
}(window));

(function(w) {
    w.app = w.app || {};

    function mapline(el, adrs, cpt, starttitle, cartitle) {
        $('body').append('<div class="idmaphide"><div id="idmaphide"></div></div>')
        var map = new BMap.Map(el || "allmap"); // 创建Map实例
        map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
        var top_right_navigation = new BMap.NavigationControl({ anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL });
        map.addControl(top_right_navigation);

        getadds(adrs || ['重庆', '北京大兴瑞海二区'], function(arr) {
            line(arr.shift(), arr, cpt, cartitle);
        });

        function line(pt, pts, cpt, cartitle) {
            var p = pt.split(',')[0],
                t = pt.split(',')[1];
            _p = pts[0].split(',')[0];
            _t = pts[0].split(',')[1];
            var p1 = new BMap.Point(p, t);
            var p2 = new BMap.Point(_p, _t);
            _cp = cpt.split(',')[0];
            _ct = cpt.split(',')[1];
            var jp = new BMap.Point(_cp || 116.37811, _ct || 39.851817);

            addicon(p, t, 'images/mp2_03.png', 34, 44, 18, 55);
            addicon(_p, _t, 'images/mp2_06.png', 34, 44, 18, 55);
            addspoticon(p, t);
            addspoticon(_p, _t);
            addtext(p, t, starttitle || '[总仓]');
            var labeltip = addtexts(_cp, _ct, cartitle)

            //map.addOverlay(new BMap.Marker(jp));
            var car = addicon(_cp, _ct, 'images/map-car.png', 32, 32, 18, 30);
            car.addEventListener('click', function() {
                if (!labeltip.show) {
                    map.addOverlay(labeltip);
                } else {
                    map.removeOverlay(labeltip);
                }
                labeltip.show = !labeltip.show;
            })

            var driving = new BMap.DrivingRoute(map)

            driving.setSearchCompleteCallback(function(results) {
                searchComplete(results);
                var pts = driving.getResults().getPlan(0).getRoute(0).getPath(); //通过驾车实例，获得一系列点的数组
                var polyline = new BMap.Polyline(pts, {
                    strokeColor: "#4fa1a4",
                    strokeWeight: 6,
                    strokeOpacity: 0.8
                });
                map.addOverlay(polyline);
            })
            map.centerAndZoom(new BMap.Point(_cp, _ct), 12);

            driving.search(p1, jp);
            driving.search(jp, p2);

            function searchComplete(results) {
                if (driving.getStatus() != BMAP_STATUS_SUCCESS) {
                    return;
                }
                var plan = results.getPlan(0);
                var output = '';
                output += plan.getDuration(true) + "\n"; //获取时间
                output += "总路程为：";
                output += plan.getDistance(true) + "\n";
                console.log(output);
            }
        }


        function addtext(p, t, text) {
            var opts = {
                position: new BMap.Point(p, t),
                offset: new BMap.Size(20, -20)
            }
            var label = new BMap.Label(text, opts);
            label.setStyle({
                color: "#fff",
                fontSize: "14px",
                lineHeight: "20px",
                border: '0px',
                padding: '4px',
                background: 'rgba(0,0,0,0.3)'
            });
            map.addOverlay(label);
        }

        function addtexts(p, t, text) {
            var opts = {
                position: new BMap.Point(p, t),
                offset: new BMap.Size(20, -20)
            }
            var label = new BMap.Label(text, opts);
            label.setStyle({
                color: "#fff",
                fontSize: "14px",
                lineHeight: "20px",
                border: '0px',
                padding: '4px',
                background: 'rgba(0,89,130,0.5)'
            });
            label.show = 0;
            //map.addOverlay(label);
            return label;
        }

        //添加icon
        function addicon(p, t, img, w, h, _l, _t) {
            var pt = new BMap.Point(p, t);
            var icon = new BMap.Icon(img, new BMap.Size(w, h));
            icon.setAnchor(new BMap.Size(_l, _t))
            var marker = new BMap.Marker(pt, { icon: icon })
            map.addOverlay(marker);
            return marker;
        }

        function addspoticon(p, t) {
            var pt = new BMap.Point(p, t);
            var icon1 = new BMap.Icon('images/mp2_11.png', new BMap.Size(20, 20));
            icon1.setAnchor(new BMap.Size(10, 10))
            var marker1 = new BMap.Marker(pt, { icon: icon1 })
            map.addOverlay(marker1);
        }
        //获取pt
        function getadds(val, call) {
            var idmaphide = new BMap.Map("idmaphide");
            idmaphide.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
            var localSearch = new BMap.LocalSearch(idmaphide);
            var arr = [];
            var index = -1;
            localSearch.enableAutoViewport();
            localSearch.setSearchCompleteCallback(function(searchResult) {　　　　
                var poi = searchResult.getPoi(0);　　　　 //console.log(poi.point.lng + "," + poi.point.lat);   
                arr.push(poi.point.lng + "," + poi.point.lat)
                if (arr.length == val.length) {
                    call(arr);
                } else {
                    ua();
                }　　
            });

            function ua() {
                if (index < val.length - 1) {
                    index++;
                    localSearch.search(val[index])
                }
            }
            ua();
        }
    }
    w.app.maplines = mapline;
}(window));
(function(w) {
    function socket(url, user) {
        var socket = io(url || 'http://117.78.47.109:8007');
        socket.on('news', function(data) {
            console.log(data);
            socket.emit('USERID', user || { name: 'csbr', id: '1' });
        });
        socket.on('message', function(data) {
            console.log(data);
            var num = data.value;
            if (data.type == 1) {
                if (num > 0) {
                    $('.g_hear a').eq(2).addClass('current')
                }
            }
        })
        socket.on('disconnect', function() {
            console.log('disconnect')
        })
    }
    w.app.socket = socket;
}(window));
$(function() {
    $('.message-list').on('click', '.btn-dshow', function() {
        $(this).parents('.msg-detail').addClass('read').find('.msg-con2').show();
        $(this).hide();
        $(this).parent().find('.btn-dhide').removeClass('hide')
        var url = $(this).attr('data-url');
        $.get(url)
    }).on('click', '.btn-dhide', function() {
        $(this).addClass('hide');
        $(this).parent().find('.btn-dshow').show();
        $(this).parents('.msg-detail').find('.msg-con2').hide();
    }).on('click', '.btn-dremove', function() {
        var url = $(this).attr('data-url');
        var par = $(this).parents('.msg-detail');
        $.get(url, {}, function(res) {
            par.remove();
        })
    })
})
var D = {
    state: [
        { id: '', name: '选择', class: 'font-red' }, { id: 1, name: '有效' }, { id: 2, name: '无效' }
    ],
    jstype: [
        { id: '', name: '选择' }, { id: 1, name: '发生定额' }, { id: 2, name: '物业费' }
    ],
    jmtype: [
        { id: '', name: '选择' }, { id: 1, name: '月' }, { id: 2, name: '季度' }
    ],
    stateb: [
        { id: '', name: '待审核', class: "font-red" }, { id: 1, name: '有效' }, { id: 2, name: '无效' }
    ],
    statec: [
        { id: 0, name: '否', class: 'font-red' },
        { id: 1, name: '是' }
    ],
    msgstate: [
        { id: 0, name: '否', class: 'font-red' },
        { id: 1, name: '是' }
    ]
}

$(function() {
    app.init();
})